﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UQualityQuestionnaireAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }

        protected override string DWZRef
        {
            get { return "UQualityQuestionnaireList"; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {

            UQualityQuestionnaireInfo obj = Request.SerializableObject<UQualityQuestionnaireInfo>();

            //obj.UserName = GetRequestValue<string>("dwz_orgLookup.UserName", "");

            if (UQualityQuestionnaireController.Add(obj) > 0)
                SuccessJson("添加成功", this.DWZRef);
            else
                ErrorJson("添加失败", this.DWZRef);
        }

        #region 获取调查表模板
        protected string GetUQuestionTemplete()
        {
            string TempHtml = "";
            TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey);
            if (!TempHtml.IsEmptyOrNull())
                return TempHtml;
            TempHtml = "";
          //  string ItemTmpHtmlTitleTemp = "<b>({0}){1}</b>";
            string ItemTmpHtmlConTemp = "<table width=\"100%\">{0}</table> ";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0, 1);
            string trhtml = "";
            int tdnum = 0;
            trhtml = "<tr>";
            foreach (UQualityTempleteInfo item in allQtemp)
            {
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                if ((tdnum % 3) == 0 && tdnum != 0)
                {
                    trhtml = trhtml + "</tr><tr>";
                }
                trhtml = trhtml + string.Format("<td><label>{0}</label>",item.QTTitle);
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    trhtml = trhtml + string.Format("<input type=\"checkbox\" name=\"UQTIDS\" value=\"{0}\" />{1}", item2.UQTID, item2.QTTitle);                   
                }
                trhtml = trhtml + "</td>";
                tdnum++;
            }
            trhtml = trhtml + "</tr>";

            ItemTmpHtmlConTemp = string.Format(ItemTmpHtmlConTemp, trhtml);
            TempHtml = ItemTmpHtmlConTemp;
            UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey, TempHtml);
            return TempHtml;
        }

        protected string GetUQualityTemplete2()
        {
            string TempHtml = "";
            TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey2);
            if (!TempHtml.IsEmptyOrNull())
                return TempHtml;
            TempHtml = "";
            string ItemTmpHtmlTitleTemp = "<b>{0}</b>";
            string ItemTmpHtmlConTemp = "<table >{0}</table>";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0,2);

            foreach (UQualityTempleteInfo item in allQtemp)
            {
                TempHtml = TempHtml + string.Format(ItemTmpHtmlTitleTemp, item.QTTitle);
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                string trhtml = "";
                int tdnum = 0;
                // item.RowTDNum = item.RowTDNum+1;
                trhtml = "<tr>";
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    if ((tdnum % item.RowTDNum) == 0 && tdnum != 0)
                    {
                        trhtml = trhtml + "</tr><tr>";
                    }
                    trhtml = trhtml + string.Format("<td><input type=\"checkbox\" name=\"UQTIDS\" value=\"{0}\">{1}</td>", item2.UQTID, item2.QTTitle);
                    tdnum++;
                }
                trhtml = trhtml + "</tr>";

                TempHtml = TempHtml + string.Format(ItemTmpHtmlConTemp, trhtml);

            }
            UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey2, TempHtml);
            return TempHtml;
        }
        #endregion
    }
}